home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / math / gle-3.000 / gle-3 / gle / drawit.c < prev    next >
C/C++ Source or Header  |  1995-02-11  |  9KB  |  328 lines

  1. #if ( defined DJ || defined EMXOS2 )      /* a.r. */
  2.         #define unix
  3. #endif
  4. #ifdef EMXOS2
  5.         extern int pmFlag;
  6. #endif
  7.  
  8. #include "all.h"
  9. #include <math.h>
  10. #include <time.h>
  11.  
  12. #if (defined M_PI && !defined PI)
  13. #define PI M_PI
  14. #define pi M_PI
  15. #elif defined PI
  16. #define pi PI
  17. #else
  18. #define PI 3.141592653
  19. #define pi 3.141592653
  20. #endif
  21.  
  22. #define true (!false)
  23. #define false 0
  24. #define dbg if (gle_debug>0)
  25. extern int done_open;
  26. extern int gle_debug;
  27. extern int trace_on;
  28. extern int netxt;
  29. extern int this_line;
  30. int32 *(*gpcode)[];   /* gpcode is a pointer to an array of poiter to int32 */
  31. int32 (*gplen)[];   /* gpcode is a pointer to an array of int32 */
  32. int ngpcode=0;
  33. extern int ngtxt;
  34. extern char *(*gtxt)[];
  35. int ngerror;
  36. extern int last_line;
  37. char *line(int i);
  38. int pass_checkmode(void);
  39. int expand_pcode(int i, int *j);
  40. char *dr_nextline(int *srclin);
  41. int dr_init(void);
  42. int getch(void);
  43. int fner(char *s);
  44. int abort_flag;
  45. static char inbuff[300];
  46. int var_def(char *s, double x);
  47. /*---------------------------------------------------------------------------*/
  48. gle_redraw()
  49. {
  50. static char xinbuff[300];
  51. char source[20];
  52. static char *tk[500];
  53. static char tkbuff[500];
  54. int ntok,f;
  55. int32 time1,time2;
  56. static int32 pcode[500];
  57. double oval;
  58. int maxpcode=0;
  59. int plen,cp,otyp,ii,i,j,al,endp;
  60. FILE *fptr;
  61. char space_str[] = " ";
  62. char fname[80],*s;
  63.         ngpcode = 0;
  64.         expand_pcode(ngtxt,&maxpcode);
  65.  
  66.         token_space();
  67.         /* Now compile the file into pcode */
  68.         for (i=0;i<500;i++) tk[i] = space_str;
  69.         abort_flag = false;
  70.         ngerror = 0;
  71.         netxt = 0;
  72.         last_line = 0;
  73.         fner("CGLE V3.3h,  Compiling...");
  74.  
  75.         mark_clear();
  76.         sub_clear();
  77.         for_init();
  78.         f_init();
  79.         dr_init();
  80. /*        var_def("PI",3.14159265); */
  81.         var_def("PI",3.14159265);
  82.         done_open = false;
  83.         for (;(s = dr_nextline(&i)) != NULL;) {
  84.                 strcpy(xinbuff,s);
  85. and_again:        al = strlen(xinbuff);
  86.                 if (xinbuff[al-1]=='&') {
  87.                         xinbuff[al-1] = 0;
  88.                         strcat(xinbuff, dr_nextline(&i));
  89.                         if (strlen(xinbuff)>290) printf("Input line too int32\n");
  90.                         goto and_again;
  91.                 }
  92.                 if (xinbuff[0]==26) xinbuff[0] = 0;
  93.                 strcpy(inbuff,xinbuff);
  94.                 this_line = i;
  95.                 if (trace_on) gprint("Source | %s \n",xinbuff);
  96.                 token(xinbuff,&tk,&ntok,tkbuff);
  97.                 plen = 0;
  98.                 passt(ngpcode+1,inbuff,&tk,&ntok,pcode,&plen);
  99. /*
  100.                 for (ii=0;ii<plen;ii++) {
  101.                 printf("%x ",pcode[ii]);
  102.                 }
  103.                 printf("\n");
  104. */
  105.                 if (ngpcode > maxpcode) expand_pcode(ngpcode*2,&maxpcode);
  106.                 (*gpcode)[++ngpcode] = myallocz(plen*sizeof(char *));
  107.                 (*gplen)[ngpcode] = plen;
  108.                 memcpy((*gpcode)[ngpcode],&pcode,plen*sizeof(char *));
  109.                 if (abort_key()) goto do_abort;
  110.         }
  111.         pass_checkmode();
  112.  
  113.         time(&time2);
  114.         fner("CGLE V3.3h,  Running...");
  115.         if (ngerror>0) {
  116.                 gprint("Abort (Y/N)  [Y] \n");
  117.                #ifdef EMXOS2            /* a.r.- prevents locking OS/2 */
  118.                 if (pmFlag == 0) {
  119.                         if (tolower(text_inkey())!='n') 
  120.                                 return;
  121.                         }
  122.                #else
  123.                 if (tolower(text_inkey())!='n') return;
  124.                #endif
  125.         }
  126.         for (i=1;i<=ngpcode;i++) {
  127.                 if (abort_key()) goto do_abort;
  128.                 this_line = i;
  129.                 if (trace_on) gprint("Trace |%s\n",line(i));
  130.                 dbg gprint("Call do_pcode[%d] \n",i);
  131. /*                printf("Pcode pointer %p %d \n",(*gpcode)[i],i);*/
  132.                 do_pcode(&i,(*gpcode)[i],(*gplen)[i],&endp);
  133.         }
  134. do_abort:
  135.         g_close();
  136.  
  137.         for (i=1;i<=ngpcode;i++) {
  138.                 this_line = i;
  139.                 if ( (*gpcode)[i] != NULL) myfrees( (*gpcode)[i] ,"gpcode");
  140.         }
  141.  
  142. }
  143. /*--------------------------------------------------------------------------*/
  144. glezzz()
  145. {
  146.         printf("~~~~~~~~~~~~~~~~~~Pcode pointer %p 2 \n",(*gpcode)[2]);
  147. }
  148. gle_include(char *s)
  149. {
  150.         gprint("include file (not implemented ) {%s} \n",s);
  151. }
  152. /*--------------------------------------------------------------------------*/
  153. extern char gleroot[];
  154. char *gle_top()
  155. {
  156.         static char s[80];
  157. #ifdef __TURBOC__
  158.         return gleroot;
  159. #elif ( defined DJ || defined EMXOS2 || defined unix)
  160.         strcpy(s,gleroot);
  161.         strcat(s, "/");
  162.         return s;
  163. #else
  164.         return "cgle_top:";
  165. #endif
  166. }
  167. char *gledir(char *s);
  168. char *bgidir()
  169. {
  170. #ifdef __TURBOC__
  171.         char *s;
  172.         s = getenv("GLE_BGI");
  173.         if (s==NULL) {
  174.                 s = gledir("");
  175.         }
  176.         return s;
  177. #endif
  178. }
  179. char *fontdir(char *fname)
  180. {
  181.         static char fbuff[80];
  182. #if ( defined DJ || defined EMXOS2 || defined unix)
  183.         strcpy(fbuff,gle_top());
  184.         strcat(fbuff,"font/");
  185. #elif __TURBOC__
  186.         strcpy(fbuff,gle_top());
  187.         strcat(fbuff,"font\\");
  188. #else
  189.         strcpy(fbuff,"cgle_top:");
  190. #endif
  191.         strcat(fbuff,fname);
  192.         return &fbuff[0];
  193. }
  194.  
  195. char *libdir(char *fname)
  196. {
  197.         static char fbuff[80];
  198. #if ( defined DJ || defined EMXOS2 || defined unix)
  199.         strcpy(fbuff,gle_top());
  200.         strcat(fbuff,"lib/");
  201. #elif __TURBOC__
  202.         strcpy(fbuff,gle_top());
  203.         strcat(fbuff,"lib\\");
  204. #else
  205.         strcpy(fbuff,"cgle_top:");
  206. #endif
  207.         strcat(fbuff,fname);
  208.         return &fbuff[0];
  209. }
  210.  
  211. char *usrlibdir(char *fname)
  212. {
  213.         char *s;
  214.         static char fbuff[80];
  215.  
  216.         s = getenv("GLE_USRLIB");
  217.         strcpy(fbuff,s);
  218. #if ( defined DJ || defined EMXOS2 || defined unix)
  219.         strcat(fbuff,"/");
  220. #elif __TURBOC__
  221.         strcat(fbuff,"\\");
  222. #else
  223.         strcpy(fbuff,"cgle_top:");
  224. #endif
  225.         strcat(fbuff,fname);
  226.         return &fbuff[0];
  227. }
  228.  
  229. char *gledir(char *fname)
  230. {
  231.         static char fbuff[80];
  232. #if ( defined DJ || defined EMXOS2 || defined unix)
  233.         strcpy(fbuff,gle_top());
  234. #elif __TURBOC__
  235.         strcpy(fbuff,gle_top());
  236.         strcat(fbuff,"exe\\");
  237. #else
  238.         strcpy(fbuff,"cgle_top:");
  239. #endif
  240.         strcat(fbuff,fname);
  241.         return &fbuff[0];
  242. }
  243. static int dri;
  244. static ninc=0;
  245. static FILE *incptr[10];
  246. include_file(char *fname)
  247. {
  248.         incptr[++ninc] = fopen(fname,"r");
  249.         if (incptr[ninc]==NULL)
  250.                    incptr[ninc] = fopen(libdir(fname),"r");
  251.         if (incptr[ninc]==NULL)
  252.                    incptr[ninc] = fopen(usrlibdir(fname),"r");
  253.         if (incptr[ninc]==NULL) {
  254.                 gprint("Unable to open input file {%s} \n",fname);
  255.                 gprint("I searched in the directories: current directory %s %s \n",
  256.                        libdir(""), usrlibdir(""));
  257.                 perror("Reason"); ninc--;
  258.         }
  259. }
  260. dr_init()
  261. {
  262.         dri = 1;
  263. }
  264. char *dr_nextline(int *srclin)
  265. {
  266.         int i;
  267. try_again:;
  268.         if (ninc==0) {
  269.                 if (dri>ngtxt) return NULL;
  270.                 *srclin = dri;
  271.                 return (*gtxt)[dri++];
  272.         } else {
  273.                 if (feof(incptr[ninc])) goto close_file;
  274.                 if (fgets(inbuff,295,incptr[ninc])==NULL) goto close_file;
  275.                 i = strlen(inbuff);
  276.                 if (inbuff[i-1]=='\n') inbuff[i-1] = 0;
  277.                 return inbuff;
  278.         }
  279. close_file:
  280.         fclose(incptr[ninc--]);
  281.         goto try_again;
  282. }
  283. expand_pcode(int ngtxt,int *maxpcode)
  284. {
  285.         int32 *a,*b;
  286.         a = myallocz((ngtxt+10)*sizeof(char *));
  287.         b = myallocz((ngtxt+10)*sizeof(char *));
  288.         if (gpcode!=0) {
  289.                 memcpy(a,gpcode,(*maxpcode + 4)*sizeof(char *));
  290.                 memcpy(b,gplen,(*maxpcode + 4)*sizeof(char *));
  291.                 myfrees(gpcode,"gpcode2");
  292.                 myfrees(gplen,"gplen");
  293.         }
  294.         gpcode = (int32 *(*)[]) a;
  295.         gplen = (int32 (*)[]) b;
  296.         *maxpcode = ngtxt+1;
  297. }
  298. run_bigfile(char *fname)
  299. {
  300.         FILE *fptr;
  301.         char inbuff[200],s[200];
  302.         char *tk[300];
  303.         char tkbuff[300];
  304.         int32 pcode[300];
  305.         int plen,ntok,i,endp;
  306.  
  307.         fptr = fopen(fname,"r");
  308.         if (fptr==NULL) {
  309.                 gprint("Unable to open bigfile {%s} \n",fname);
  310.                 perror("Reason");
  311.                 return;
  312.         }
  313.         for (;!feof(fptr);) {
  314.          if (fgets(inbuff,190,fptr)!=NULL) {
  315.                 strcpy(s,inbuff);
  316.                 i = strlen(inbuff);
  317.                 if (inbuff[i-1]=='\n') inbuff[i-1] = 0;
  318.                 if (trace_on) gprint("Source | %s \n",inbuff);
  319.                 token(inbuff,&tk,&ntok,tkbuff);
  320.                 plen = 0;
  321.                 passt(ngpcode+1,s,&tk,&ntok,pcode,&plen);
  322.                 do_pcode(&i,pcode,plen,&endp);
  323.          }
  324.         }
  325.         fclose(fptr);
  326. }
  327.  
  328.